<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
    <link rel="stylesheet" href="../../styles/common.css" />
    <link rel="stylesheet" href="../../styles/page.css" />
</head>
<body>
<div class="dashboard-container" id="category-app">
    <div class="container">
<!--        <div-->
<!--                class="tableBar"-->
<!--                style="display: inline-block"-->
<!--        >-->
<!--            <el-input-->
<!--                    v-model="input"-->
<!--                    placeholder="请输入分类名"-->
<!--                    style="width: 250px"-->
<!--                    clearable-->
<!--                    @keyup.enter.native="handleQuery"-->
<!--            >-->
<!--                <i-->
<!--                        slot="prefix"-->
<!--                        class="el-input__icon el-icon-search"-->
<!--                        style="cursor: pointer"-->
<!--                        @click="handleQuery"-->
<!--                ></i>-->
<!--            </el-input>-->

<!--            <el-button type="primary" class="continue" @click="addClass()">+新增</el-button>-->
<!--        </div>-->
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="订单编号">
                <el-input v-model="formInline.id" placeholder="审批人"></el-input>
            </el-form-item>
            <el-form-item label="服务类型">
                <el-select v-model="formInline.typeId" placeholder="请选择">
                    <el-option
                            v-for="item in subTypeList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="下单时间">
                <el-date-picker
                        value-format="yyyy-MM-dd HH:mm:ss"
                        v-model="formInline.createTime"
                        type="datetime"
                        placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleQuery">查询</el-button>
            </el-form-item>
        </el-form>

        <el-table
                :data="tableData"
                stripe
                class="tableBox"
        >
            <el-table-column
                    prop="id"
                    label="订单编号"
            /></el-table-column>
            <el-table-column
                    prop="subName"
                    label="预约名称"
            /></el-table-column>
            <el-table-column
                    prop="typeName"
                    label="服务类型"
            ></el-table-column>
            <el-table-column
                    prop="money"
                    label="订单费用"
            ></el-table-column>
            <el-table-column
                    prop="subUser"
                    label="预约者"
            ></el-table-column>
            <el-table-column
                    prop="createUser"
                    label="创建者"
            ></el-table-column>
            <el-table-column
                    prop="remarks"
                    label="备注"
            ></el-table-column>
            <el-table-column
                    prop="createTime"
                    label="下单时间"
            ></el-table-column>
            <el-table-column
                    label="操作"
                    width="160"
                    align="center"
            >
                <template slot-scope="scope">
                    <el-button
                            type="text"
                            size="small"
                            type="warning"
                            class="non"
                            @click="deleteHandle(scope.row)"
                    >
                        详情
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                class="pageList"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="counts"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
    <el-dialog
            :title="classData.title"
            :visible.sync="classData.dialogVisible"
            width="30%"
            :before-close="handleClose"
    >
        <el-form
                class="demo-form-inline"
                label-width="100px"
        >
            <el-form-item label="审批说明">
                <el-input
                        type="textarea"
                        :rows="2"
                        placeholder="请输入审批说明"
                        v-model="classData.approveDesc">
                </el-input>
            </el-form-item>
        </el-form>
        <span
                slot="footer"
                class="dialog-footer"
        >
        <el-button
                size="medium"
                @click="classData.dialogVisible = false"
        >取 消</el-button>
        <el-button
                type="primary"
                size="medium"
                @click="submitForm(1)"
        >通过</el-button>
        <el-button
                type="primary"
                size="medium"
                class="continue"
                @click="submitForm(2)"
        > 不通过 </el-button>
      </span>
    </el-dialog>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/subscribe-order-list.js"></script>
<script>
    new Vue({
        el: '#category-app',
        data() {
            return {
                input:'',
                action: '',
                counts: 0,
                page: 1,
                pageSize: 10,
                tableData: [],
                type :'',
                classData: {
                    'title': '添加预约服务分类',
                    'dialogVisible': false,
                    'name': '',
                    'id':'',
                    'approveDesc': ''
                },
                formInline:{
                    id: '',
                    typeId: '',
                    createTime:''
                },
                subTypeList: []
            }
        },
        computed: {},
        created() {
            this.init()
            this.getSubTypeList()
        },
        mounted() {
        },
        methods: {
            async init () {
                console.log(this.formInline.createTime)
                await getSubscribeOrderPage(
                    {
                        'page': this.page,
                        'pageSize': this.pageSize,
                        'id': this.formInline.id ? this.formInline.id : undefined,
                        'typeId': this.formInline.typeId ? this.formInline.typeId : undefined,
                        'createTime': this.formInline.createTime ? this.formInline.createTime : undefined
                    }
                ).then(res => {
                    if (String(res.code) === '1') {
                        this.tableData = res.data.list
                        this.counts = Number(res.data.total)
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            //获取预约服务列表
            getSubTypeList() {
                queryTypeList().then(res =>{
                    if (String(res.code) === '1') {
                        this.subTypeList = res.data
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            //新增分类信息
            addClass(){
                this.classData.title = '新增分类'
                this.action = 'add'
                this.classData.name = ''
                this.classData.descInfo = ''
                this.classData.dialogVisible = true
            },
            // 添加
            editHandle(dat) {
                this.classData.title = '服务预约审批'
                this.classData.descInfo = dat.descInfo
                this.classData.id = dat.id
                this.classData.dialogVisible = true
            },
            // 关闭弹窗
            handleClose(st) {
                this.classData.dialogVisible = false
            },
            //删除分类
            deleteHandle(row){
                this.id = row.id
                this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
                    'confirmButtonText': '确定',
                    'cancelButtonText': '取消',
                    'type': 'warning'
                }).then(() => {
                    deleCategory(this.id).then(res => {
                        if (String(res.code) === '1') {
                            this.$message.success('删除成功！')
                            this.handleQuery()
                        }
                    }).catch(err => {
                        this.$message.error('请求出错了：' + err)
                    })
                })
            },
            //数据提交
            submitForm(st) {
                const classData = this.classData
                const valid = (classData.approveDesc === 0 ||classData.approveDesc)
                if (valid) {
                    approveSubscribe({'id':this.classData.id, 'approveDesc': this.classData.approveDesc,'status':st}).then(res => {
                        if (res.code === 1) {
                            this.$message.success(res.msg || '审批成功')
                            this.classData.dialogVisible = false
                            this.handleQuery()
                        } else {
                            this.$message.error(res.msg || '操作失败')
                        }
                    }).catch(err => {
                        this.$message.error('请求出错了：' + err)
                    })
                } else {
                    this.$message.error('请输入分类名称')
                }
            },
            handleSizeChange (val) {
                this.pageSize = val
                this.init()
            },
            handleCurrentChange (val) {
                this.page = val
                this.init()
            }
        }
    })
</script>
</body>
</html>